using System;
using System.Collections;
using System.Drawing;

namespace SiRtEt
{
	/// <summary>
	/// The Square Block
	/// </summary>
	public class SquareBlock : BlockBase
    {
        #region Constructor : Initialization
        /// <summary>
		/// Constructor : Initializes the properties for the square
		/// </summary>
		public SquareBlock(TheWorld theWorld):base(theWorld)
		{
			X		= Columns/2;
			Y		= 0;
			MyColor	= System.Drawing.Color.Red;
		}

		#endregion

		#region Methods
		public override System.Collections.ArrayList UsedSquares()
		{
			ArrayList usedSquares = new ArrayList();
			Width = 2; Height = 2;
			int squareIndex = X+Y*Columns; // This one gices the top left square index
			// Adding those indices which make the Square Block
			usedSquares.Add(squareIndex);
			usedSquares.Add(squareIndex + 1); // The right one on top 
			usedSquares.Add(squareIndex + Columns); // The left at bottom
			usedSquares.Add(squareIndex + Columns + 1); // The right one at bottom

			return usedSquares;
		}

		public override void Preview(Graphics renderArea)
		{
			int sqWidth = BelongsTo.UnitSquareWidth-2;
			Rectangle r = new Rectangle();

			r = new Rectangle( sqWidth, sqWidth, sqWidth,sqWidth);	
			renderArea.FillRectangle(new SolidBrush(MyColor),r);

			r = new Rectangle( 2 * sqWidth, sqWidth, sqWidth,sqWidth);
			renderArea.FillRectangle(new SolidBrush(MyColor),r);

			r = new Rectangle( sqWidth, 2 * sqWidth, sqWidth,sqWidth);
			renderArea.FillRectangle(new SolidBrush(MyColor),r);

			r = new Rectangle( 2 * sqWidth, 2 * sqWidth, sqWidth,sqWidth);
			renderArea.FillRectangle(new SolidBrush(MyColor),r);
		}
		#endregion
	}

	/// <summary>
	/// Class for the L Shaped Block
	/// </summary>
	public class LShapedBlock : BlockBase
	{
		#region Constructor : Initialization
		/// <summary>
		/// Constructor : Initializes the properties of the L Shaped Block
		/// </summary>
		public LShapedBlock(TheWorld theWorld):base(theWorld)
		{
			X = Columns/2;
			Y=0;
			MyColor = Color.Crimson;
		}
		#endregion

		#region Methods
        /// <summary>
        /// Returns the list of squares that are used by this block
        /// </summary>
        /// <returns></returns>
		public override ArrayList UsedSquares()
		{
			ArrayList usedSquares = new ArrayList();
			int squareIndex = X + Y*Columns;

			switch(RotateAngle)
			{
				case 0:
					usedSquares.Add(squareIndex);				//		.
					usedSquares.Add(squareIndex + Columns);		//		.
					usedSquares.Add(squareIndex + 2*Columns);	//		..
					usedSquares.Add(squareIndex + 2*Columns+1);	//		 ^

					Width = 2; Height = 3;
					break;

				case 90:
					usedSquares.Add(squareIndex);					//		...
					usedSquares.Add(squareIndex + 1);				//		.^
					usedSquares.Add(squareIndex + 2);				//		  ^
					usedSquares.Add(squareIndex + Columns);			//		^

					Width = 3; Height = 2;
					break;

				case 180:
					usedSquares.Add(squareIndex);					//		..
					usedSquares.Add(squareIndex + 1);				//		 .
					usedSquares.Add(squareIndex + Columns + 1);		//		 .
					usedSquares.Add(squareIndex + 2*Columns+ 1);	//		 

					Width = 2; Height = 3;
					break;

				case 270:
					usedSquares.Add(squareIndex+2);				//		  .
					usedSquares.Add(squareIndex + Columns);		//		...
					usedSquares.Add(squareIndex + Columns +1);	//		
					usedSquares.Add(squareIndex + Columns +2);	//		 

					Width = 3; Height = 2;
					break;
			}
			return usedSquares;
		}

        /// <summary>
        /// Draws the preview for this block on the specified Graphics surface
        /// </summary>
        /// <param name="renderArea">The area to draw the preview in</param>
		public override void Preview(Graphics renderArea)
		{
			int sqWidth = BelongsTo.UnitSquareWidth - 2;
			Rectangle r = new Rectangle();

			r = new Rectangle( sqWidth, sqWidth, sqWidth,sqWidth);	
			renderArea.FillRectangle(new SolidBrush(MyColor),r);

			r = new Rectangle( sqWidth, 2 * sqWidth, sqWidth,sqWidth);
			renderArea.FillRectangle(new SolidBrush(MyColor),r);

			r = new Rectangle( sqWidth, 3 * sqWidth, sqWidth,sqWidth);
			renderArea.FillRectangle(new SolidBrush(MyColor),r);

			r = new Rectangle( 2 * sqWidth, 3 * sqWidth, sqWidth,sqWidth);
			renderArea.FillRectangle(new SolidBrush(MyColor),r);
		}

		#endregion
	}

	/// <summary>
	/// The Gamma Shaped Block
	/// </summary>
	public class GammaShapedBlock : BlockBase
	{
		#region Constructor : Initialization
		public GammaShapedBlock(TheWorld theWorld):base(theWorld)
		{
			X = Columns/2;
			Y =0;
			MyColor = Color.Tomato;
		}
		#endregion

		#region 
        /// <summary>
        /// Returns the list of squares that are used by this block
        /// </summary>
        /// <returns></returns>
		public override ArrayList UsedSquares()
		{
			ArrayList usedSquares = new ArrayList();
			int squareIndex = X + Y*Columns;

			switch(RotateAngle)
			{
				case 0:
					usedSquares.Add(squareIndex+1);					//		 .
					usedSquares.Add(squareIndex + Columns + 1);		//		 .
					usedSquares.Add(squareIndex + 2*Columns);	//		..
					usedSquares.Add(squareIndex + 2*Columns +1);	//		 

					Width = 2; Height = 3;
					break;

				case 90:
					usedSquares.Add(squareIndex);						//	.	
					usedSquares.Add(squareIndex + Columns);				//	...	
					usedSquares.Add(squareIndex + Columns +1);			//		 
					usedSquares.Add(squareIndex + Columns +2);			//		

					Width = 3; Height = 2;
					break;

				case 180:
					usedSquares.Add(squareIndex);					//		 ..
					usedSquares.Add(squareIndex + 1);				//		 .
					usedSquares.Add(squareIndex + Columns);			//		 .
					usedSquares.Add(squareIndex + 2*Columns);		//		 

					Width = 2; Height = 3;
					break;

				case 270:
					usedSquares.Add(squareIndex);					//	
					usedSquares.Add(squareIndex + 1);				//		...
					usedSquares.Add(squareIndex + 2);				//		  .
					usedSquares.Add(squareIndex + Columns +2);		//		 

					Width = 3; Height = 2;
					break;
			}
			return usedSquares;
		}

        /// <summary>
        /// Draws the preview for this block on the specified Graphics surface
        /// </summary>
        /// <param name="renderArea">The area to draw the preview in</param>
		public override void Preview(Graphics renderArea)
		{
			int sqWidth = BelongsTo.UnitSquareWidth-2;
			Rectangle r = new Rectangle();

			r = new Rectangle( 2 * sqWidth, sqWidth, sqWidth,sqWidth);	
			renderArea.FillRectangle(new SolidBrush(MyColor),r);

			r = new Rectangle( 2 * sqWidth, 2 * sqWidth, sqWidth,sqWidth);
			renderArea.FillRectangle(new SolidBrush(MyColor),r);

			r = new Rectangle( sqWidth, 3 * sqWidth, sqWidth,sqWidth);
			renderArea.FillRectangle(new SolidBrush(MyColor),r);

			r = new Rectangle( 2 * sqWidth, 3 * sqWidth, sqWidth,sqWidth);
			renderArea.FillRectangle(new SolidBrush(MyColor),r);
		}

		#endregion
	}


	/// <summary>
	/// The I shaped block... or the Line
	/// </summary>
	public class IShapedBlock : BlockBase
	{
		#region Constructor : Initialization
		public IShapedBlock(TheWorld theWorld):base(theWorld)
		{
			X = Columns/2;
			Y = 0;
			MyColor = Color.Turquoise;
		}
		#endregion
		
		#region Methods
        /// <summary>
        /// Returns the list of squares that are used by this block
        /// </summary>
        /// <returns></returns>
		public override ArrayList UsedSquares()
		{
			ArrayList usedSquares = new ArrayList();
			int squareIndex = X + Y * Columns;
			switch(RotateAngle)
			{
				case 0:
				case 180:
					usedSquares.Add(squareIndex);				//		.
					usedSquares.Add(squareIndex + Columns	);	//		.
					usedSquares.Add(squareIndex + 2*Columns );	//		.
					usedSquares.Add(squareIndex + 3*Columns );	//		. 

					Width = 1; Height = 4;
					break;

				case 90:
				case 270:
					usedSquares.Add(squareIndex);					//		....
					usedSquares.Add(squareIndex + 1);				//		
					usedSquares.Add(squareIndex + 2);				//		 
					usedSquares.Add(squareIndex + 3);				//		

					Width = 4; Height = 1;
					break;
			}
			return usedSquares;
		}

        /// <summary>
        /// Draws the preview for this block on the specified Graphics surface
        /// </summary>
        /// <param name="renderArea">The area to draw the preview in</param>
		public override void Preview(Graphics renderArea)
		{
			int sqWidth = BelongsTo.UnitSquareWidth -2;
			Rectangle r = new Rectangle();

			r = new Rectangle( sqWidth, sqWidth, sqWidth,sqWidth);	
			renderArea.FillRectangle(new SolidBrush(MyColor),r);

			r = new Rectangle( sqWidth, 2 * sqWidth, sqWidth,sqWidth);
			renderArea.FillRectangle(new SolidBrush(MyColor),r);

			r = new Rectangle( sqWidth, 3 * sqWidth, sqWidth,sqWidth);
			renderArea.FillRectangle(new SolidBrush(MyColor),r);

			r = new Rectangle( sqWidth, 4 * sqWidth, sqWidth,sqWidth);
			renderArea.FillRectangle(new SolidBrush(MyColor),r);
		}
		#endregion
	}

	/// <summary>
	/// The Z Shaped block
	/// </summary>
	public class ZBlock : BlockBase
	{
		#region Constructor : Initialization
		/// <summary>
		/// Constructor : Initializes the properties for the square
		/// </summary>
		public ZBlock(TheWorld theWorld):base(theWorld)
		{
			X		= Columns/2;
			Y		= 0;
			MyColor	= System.Drawing.Color.BlueViolet;
		}

		#endregion

		#region Methods
        /// <summary>
        /// Returns the list of squares that are used by this block
        /// </summary>
        /// <returns></returns>
		public override System.Collections.ArrayList UsedSquares()
		{
			ArrayList usedSquares = new ArrayList();
			int squareIndex = X+Y*Columns; // This one gices the top left square index
			switch(RotateAngle)
			{
				case 0:					
				case 180:
					Width = 3; Height = 2;
					usedSquares.Add(squareIndex);							//  ..
					usedSquares.Add(squareIndex + 1);						//   ..
					usedSquares.Add(squareIndex + Columns+1);
					usedSquares.Add(squareIndex + Columns + 2);
					break;
				case 90:
				case 270:
					Width = 2; Height = 3;
					usedSquares.Add(squareIndex + 1);						//   .
					usedSquares.Add(squareIndex + Columns );				//  .. 
					usedSquares.Add(squareIndex + Columns+1);				//  .
					usedSquares.Add(squareIndex + 2*Columns);
					break;	
			}
			return usedSquares;
		}

        /// <summary>
        /// Draws the preview for this block on the specified Graphics surface
        /// </summary>
        /// <param name="renderArea">The area to draw the preview in</param>
		public override void Preview(Graphics renderArea)
		{
			int sqWidth = BelongsTo.UnitSquareWidth-2;
			Rectangle r = new Rectangle();

			r = new Rectangle( sqWidth, sqWidth, sqWidth,sqWidth);	
			renderArea.FillRectangle(new SolidBrush(MyColor),r);

			r = new Rectangle( 2 * sqWidth, sqWidth, sqWidth,sqWidth);
			renderArea.FillRectangle(new SolidBrush(MyColor),r);

			r = new Rectangle( 2 * sqWidth, 2 * sqWidth, sqWidth,sqWidth);
			renderArea.FillRectangle(new SolidBrush(MyColor),r);

			r = new Rectangle( 3 * sqWidth, 2 * sqWidth, sqWidth,sqWidth);
			renderArea.FillRectangle(new SolidBrush(MyColor),r);
		}
		#endregion
	}

	/// <summary>
	/// The S Shaped block
	/// </summary>
	public class SBlock : BlockBase
    {
        #region Constructor : Initialization
        /// <summary>
		/// Constructor : Initializes the properties for the square
		/// </summary>
		public SBlock(TheWorld theWorld):base(theWorld)
		{
			X		= Columns/2;
			Y		= 0;
			MyColor	= System.Drawing.Color.SpringGreen;
		}

		#endregion

		#region Methods
        /// <summary>
        /// Returns the list of squares that are used by this block
        /// </summary>
        /// <returns></returns>
		public override System.Collections.ArrayList UsedSquares()
		{
			ArrayList usedSquares = new ArrayList();
			int squareIndex = X+Y*Columns; // This one gices the top left square index
			switch(RotateAngle)
			{
				case 0:					
				case 180:
					Width = 3; Height = 2;
					usedSquares.Add(squareIndex + 1);						//   ..
					usedSquares.Add(squareIndex + 2);						//  ..
					usedSquares.Add(squareIndex + Columns);
					usedSquares.Add(squareIndex + Columns + 1);
					break;
				case 90:
				case 270:
					Width = 2; Height = 3;
					usedSquares.Add(squareIndex );							//   .
					usedSquares.Add(squareIndex + Columns);					//   ..
					usedSquares.Add(squareIndex + Columns + 1);				//    . 
					usedSquares.Add(squareIndex + 2*Columns + 1);
					break;	
			}
			return usedSquares;
		}

        /// <summary>
        /// Draws the preview for this block on the specified Graphics surface
        /// </summary>
        /// <param name="renderArea">The area to draw the preview in</param>
		public override void Preview(Graphics renderArea)
		{
				int sqWidth = BelongsTo.UnitSquareWidth-2;
				Rectangle r = new Rectangle();

				r = new Rectangle( 2 * sqWidth, sqWidth, sqWidth,sqWidth);	
				renderArea.FillRectangle(new SolidBrush(MyColor),r);

				r = new Rectangle( 3 * sqWidth, sqWidth, sqWidth,sqWidth);
				renderArea.FillRectangle(new SolidBrush(MyColor),r);

				r = new Rectangle( sqWidth, 2 * sqWidth, sqWidth,sqWidth);
				renderArea.FillRectangle(new SolidBrush(MyColor),r);

				r = new Rectangle( 2 * sqWidth, 2 * sqWidth, sqWidth,sqWidth);
				renderArea.FillRectangle(new SolidBrush(MyColor),r);
		}
		#endregion
	}

	/// <summary>
	/// The Z Shaped block
	/// </summary>
	public class TBlock : BlockBase
    {
        #region Constructor : Initialization
        /// <summary>
		/// Constructor : Initializes the properties for the square
		/// </summary>
		public TBlock(TheWorld theWorld):base(theWorld)
		{
			X		= Columns/2;
			Y		= 0;
			MyColor	= System.Drawing.Color.YellowGreen;
		}

		#endregion

		#region Methods
        /// <summary>
        /// Returns the list of squares that are used by this block
        /// </summary>
        /// <returns></returns>
		public override System.Collections.ArrayList UsedSquares()
		{
			ArrayList usedSquares = new ArrayList();
			int squareIndex = X+Y*Columns; // This one gices the top left square index
			switch(RotateAngle)
			{
				case 0:					
					Width = 3; Height = 2;
					usedSquares.Add(squareIndex + 1);							//    .
					usedSquares.Add(squareIndex + Columns);						//   ...
					usedSquares.Add(squareIndex + Columns + 1);
					usedSquares.Add(squareIndex + Columns + 2);
					break;
				case 90:
					Width = 2; Height = 3;
					usedSquares.Add(squareIndex + 1);							//    .
					usedSquares.Add(squareIndex + Columns);						//   ..
					usedSquares.Add(squareIndex + Columns + 1);					//    .
					usedSquares.Add(squareIndex + 2*Columns + 1);
					break;
				case 180:
					Width = 3; Height = 2;
					usedSquares.Add(squareIndex );							//    
					usedSquares.Add(squareIndex + 1);						//   ...
					usedSquares.Add(squareIndex + 2);						//    .
					usedSquares.Add(squareIndex + Columns + 1);
					break;
				case 270:
					Width = 2; Height = 3;
					usedSquares.Add(squareIndex);							//  . 
					usedSquares.Add(squareIndex + Columns );				//  .. 
					usedSquares.Add(squareIndex + Columns+1);				//  .
					usedSquares.Add(squareIndex + 2*Columns);
					break;	
			}
			return usedSquares;
		}

        /// <summary>
        /// Draws the preview for this block on the specified Graphics surface
        /// </summary>
        /// <param name="renderArea">The area to draw the preview in</param>
		public override void Preview(Graphics renderArea)
		{
			int sqWidth = BelongsTo.UnitSquareWidth-2;
			Rectangle r = new Rectangle();

			r = new Rectangle( 2 * sqWidth, sqWidth, sqWidth,sqWidth);	
			renderArea.FillRectangle(new SolidBrush(MyColor),r);

			r = new Rectangle( sqWidth, 2 * sqWidth, sqWidth,sqWidth);
			renderArea.FillRectangle(new SolidBrush(MyColor),r);

			r = new Rectangle( 2 * sqWidth, 2 * sqWidth, sqWidth,sqWidth);
			renderArea.FillRectangle(new SolidBrush(MyColor),r);

			r = new Rectangle( 3 * sqWidth, 2 * sqWidth, sqWidth,sqWidth);
			renderArea.FillRectangle(new SolidBrush(MyColor),r);
		}
		#endregion
	}
}
